﻿using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GPSCrowdSource.UI {

  public delegate void Any();

  /// <summary>
  /// Status control
  /// </summary>
  public abstract class Status {
    private static Label myLabel;
    private static ProgressBar myBar;

    /// <summary>
    /// Initialize the status control utility.
    /// </summary>
    public static void Init(Label inLbl, ProgressBar bar) {
      myLabel = inLbl;
      myBar = bar;
      }

    /// <summary>
    /// Set the U/I progress bar value.
    /// </summary>
    public static void SetProgress(int min, int max, int value) {
      if(myBar == null) return;

      Any a = delegate() {
        if(min != -1)
          myBar.Minimum = min;
        if(max != -1)
          myBar.Maximum = min;
        if(value != -1)
          myBar.Value = value;
        };

      if(myBar != null && myBar.IsHandleCreated && myBar.InvokeRequired)
        myBar.BeginInvoke(a);
      else
        a();
      } 

    /// <summary>
    /// Set the U/I status value.
    /// </summary>
    public static String Message {
      set {
        if(myLabel == null) return;
        Any a = delegate() {
          };

        if(myLabel.IsHandleCreated && myLabel.InvokeRequired)
          myLabel.BeginInvoke(a);
        else
          a();
        }
      }
    }

  }
